//信息提示变量
var messageCodeError="error";
var messageCodeFaild="faild";
var messageCodeSuccess="success";

//AMR相关常量配置 pda中sqlite数据库路径

//pda中sqlite数据库文件的路径 如pda在电脑上显示为i盘。则数据库文件在i:/mobiledb/RFDB
var AMR_sqliteDbFilePath="/mobile_dbfile/chao_biao_shuju";//RFDB chao_biao_wenjian

//AMI相关常量配置 pda中sqlite数据库路径

var sqliteDbFilePath="/mobile_dbfile/chao_biao_shuju";

function colformatDate(val,row){
	if(val!=null && val!=undefined){
		var date = new Date(val);
		return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
	}
	return val;
}

function colformatDateYMDHM(val,row){
	if(val!=null && val!=undefined){
		var date = new Date(val);
		var h =  date.getHours();
		if(h<10){
			h = "0"+h;
		}

		var m =  date.getMinutes();
		if(m<10){
			m = "0"+m;
		}
		
		return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()+ ' ' +h+':'+m;
	}
	return val;
}
/**
 * 提示信息显示
 * @param {Object} json
 */
 function showMessage(title,json){
	  if(json.records[0].messageCode == messageCodeError){ 
   	  		$.messager.alert(title,json.records[0].messageDesc,'error');
     }else if(json.records[0].messageCode == messageCodeFaild){ 
   	  		$.messager.alert(title,json.records[0].messageDesc,'warning');
     }else if(json.records[0].messageCode == messageCodeSuccess){
         	$.messager.alert(title,json.records[0].messageDesc,'info');
     }	 
 }
/**
 *添加tab页

 *参数：tit 标题     url tab页连接   tabs 所在区域id
 */
function addTab(tit,url,tabs,target){
	var obj;
	if(target!=null && target.length>0 && target=="parent")
		obj=parent;
	else if(target!=null && target.length>0 && target=="parent.parent")
		obj=parent.parent; 
	else
		obj=this;

	if(obj.$(tabs).tabs('exists',tit)){
		obj.$(tabs).tabs('select',tit);
		obj.$(tabs).tabs('close',tit);
		var context ='<iframe scrolling="yes" id="'+tit+'" name="'+tit+'" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
	  		 obj.$(tabs).tabs('add',{
			 title:tit,
			 content:context,
			 closable:true
	   });
	}else{
	   var context ='<iframe scrolling="yes"  id="'+tit+'" name="'+tit+'" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
	   obj.$(tabs).tabs('add',{
		title:tit,
		content:context,
		closable:true
		});
	}
}

/**
 * 
 *获取页面所有input输入框的值组合成json数据，以提交到后台用
 *
 */
 function getFormElements(){
        var restr="";
     	var fields = $(":input").serializeArray(); 
     	jQuery.each(fields, function(i, field){ 
        	
        	 if(field.type !="button" || field.type !="img"){
        	 	restr +=field.name +":'"+field.value+"',";
        	 }
        });
        
     
        
        return "{"+restr+"}";
     }
 /**
 * 
 *获取页面所有input输入框的值组合成URL传送到数据，以提交到后台用
 *
 */
 function getFormElementsForUrl(){
        var restr="";
     	var fields = $(":input").serializeArray(); 
     	jQuery.each(fields, function(i, field){ 
        	
        	 if(field.type !="button" || field.type !="img"){
        		 if(restr=="")
        			 restr += field.name +"="+field.value+"";
        		 else
        	 	     restr +="&" + field.name +"="+field.value+"";
        	 }
        });
     	
        return  encodeURI(encodeURI("?" + restr ));
     }
  /**
   * 时间格式化  YYYY-MM-dd hh:mm:ss
   * @param {Object} ver
   * @return {TypeName} 
   */
   function dateFormatter(ver){	
	   if(ver=="" || ver==null){
		   return " ";
	   }else{
	    var now = ver.split(" ");
	    var year = now[5];
	    var month = getMonth(now[1]);
	    var day = now[2];
	    var hhmmss = now[3];
	
        return year+"-"+month+"-"+day+" "+hhmmss;
	   }
	}
	/**
   * 时间格式化  YYYY-MM-dd
   * @param {Object} ver
   * @return {TypeName} 
   */
   function dateFormatter1(ver){	
	   if(ver=="" || ver==null){
		   return " ";
	   }else{
	    var now = ver.split(" ");
	    var year = now[5];
	    var month = getMonth(now[1]);
	    var day = now[2];
	
        return year+"-"+month+"-"+day;
	   }
	}
    function getMonth(month){              
      var month_temp; 
      if(month == 'Jan'){
         month_temp='01';
      }  
       if(month == 'Feb'){
         month_temp='02';
      }  
       if(month == 'Mar'){
         month_temp='03';
      }  
       if(month == 'Apr'){
         month_temp='04';
      }  
       if(month == 'May'){
         month_temp='05';
      }  
       if(month == 'Jun'){
         month_temp='06';
      }  
       if(month == 'Jul'){
         month_temp='07';
      }  
       if(month == 'Aug'){
         month_temp='08';
      }  
       if(month == 'Sep'){
         month_temp='09';
      }  
       if(month == 'Oct'){
         month_temp='10';
      }  
       if(month == 'Nov'){
         month_temp='11';
      }  
       if(month == 'Dec'){
         month_temp='12';
      }  
      
      return month_temp;
   }  
	
	
	/**
   * 时间格式化  YYYY-MM-dd hh:mm:ss
   * @param {Object} ver
   * @return {TypeName} 
   */
   
    function formatDate(now){              
	               var   year=now.getYear();           
	               var   month=now.getMonth()+1;        
	               var   day=now.getDate();             
	               var   hour=now.getHours(); 
	               var   minute=now.getMinutes(); 
	               var   second=now.getSeconds(); 
	               return  hour+":"+minute+":"+second;             
	               }  
	               
	function formatDateByDay(now){              
	               var   year=now.getYear();           
	               var   month=now.getMonth()+1;        
	               var   day=now.getDate();             
	               var   hour=now.getHours(); 
	               var   minute=now.getMinutes(); 
	               var   second=now.getSeconds(); 
	               return  year+"-"+month+"-"+day;             
	               }  
	    
	
  /**
   * 获取当前时间  YYYYMMdd
   * @param {Object} ver
   * @return {TypeName} 
   */
  function getDateForStr(){
		var date=new Date();
		var year=date.getFullYear();
        var month=date.getMonth()>8?date.getMonth()+1:"0"+(date.getMonth()+1);
        var day=date.getDate()>9?date.getDate():"0"+(date.getDate());
        return year+month+day;
	}
   /**
   * 精确到两位小数

   * @param {Object} str
   * @return {TypeName} 
   */
  function strFormatterTotwo(str){
	    var f ="";
	    if(str != null ){
	    	f = Number(str).toFixed(2);
	    }
        return f;
	}
  /**
   * 设置txt的值
   * @param {Object} txtId 
   * @param {Object} value
   */
  function setTextValue(txtId,value){
	$("#"+txtId).attr("value",value);
  }
  
  
  function setText(txtId,value){
	$("#"+txtId).text(value);
  }
  

	/**
	 * 判断输入是否是正整数或正小数，并精确到2位小数
	 * @param {Object} s
	 * @return {TypeName} 
	 */
	function isdigit(s) {
	    var userreg = /^\d+\.?\d{0,2}$/;
	    return (userreg.test(s)) ? 1 : 0;
	}
	/**
	 * 判断输入是否是正整数
	 * @param {Object} s
	 * @return {TypeName} 
	 */
	function isdigitInt(s) {
	    var userreg = /^\d+$/;
	    return (userreg.test(s)) ? 1 : 0;
	}
	/**
	 * 判断输入是否是正整数或正小数，并精确到1位小数
	 * @param {Object} s
	 * @return {TypeName} 
	 */
	function isdigitOne(s) {
	    var userreg = /^\d+\.?\d{0,1}$/;
	    return (userreg.test(s)) ? 1 : 0;
	}
   /**
	 * 查询更多条件切换
	 * @param {Object} s
	 * @return {TypeName} 
	 */
	function searchtab(tab1,tab2) {
	   	tab1.style.display="none";
	   	tab2.style.display="block";
	}
	
	/**
	 * 检查pda是否已插上。返回数据库文件路径
	 * @return {TypeName} 
	 */
	function ShowDriveList()
	 {   
		 var fso, s, n, e, x;  
		var arrayObj=['','','','','',''];
	
		 fso = new ActiveXObject("Scripting.FileSystemObject");   
		 e = new Enumerator(fso.Drives);   
		 s = "";   
		 var j=0;
		 for (; !e.atEnd(); e.moveNext())   {
			 x = e.item();      
			 s = s + x.DriveLetter;      
			 s += " - ";      
			 if (x.DriveType == 3)
			 {
				n = x.ShareName;      
			 }
			 else if (x.IsReady)
			 {         
				n = x.VolumeName;
				arrayObj[j]=x.DriveLetter;
			 }
			 else
			 {         
			 	n = "[Drive not ready]";
			 }
			 s +=   n + "<br>";   
			 j=j+1;
		 }  
		
		 //显示所有可用的盘符
		 var fileName;
		 var filePath="";
		 for(var i=0;i<arrayObj.length;i++)
		 {
			if(arrayObj[i]!='')
			{
				fileName = fso.FileExists(arrayObj[i]+":"+sqliteDbFilePath); 
				if (fileName){
					filePath=arrayObj[i]+":"+sqliteDbFilePath;
					break;
				}
	
			}
		 }
		 
		return filePath;
		 
	 }
	
	/**
	 * 检查pda是否已插上。返回数据库文件路径
	 * @return {TypeName} 
	 */
	function AmrShowDriveList()
	 {   
		 var fso, s, n, e, x;  
		var arrayObj=['','','','','',''];
	
		 fso = new ActiveXObject("Scripting.FileSystemObject");   
		 e = new Enumerator(fso.Drives);   
		 s = "";   
		 var j=0;
		 for (; !e.atEnd(); e.moveNext())   {
			 x = e.item();      
			 s = s + x.DriveLetter;      
			 s += " - ";      
			 if (x.DriveType == 3)
			 {
				n = x.ShareName;      
			 }
			 else if (x.IsReady)
			 {         
				n = x.VolumeName;
				arrayObj[j]=x.DriveLetter;
			 }
			 else
			 {         
			 	n = "[Drive not ready]";
			 }
			 s +=   n + "<br>";   
			 j=j+1;
		 }  
		
		 //显示所有可用的盘符
		 var fileName;
		 var filePath="";
		 for(var i=0;i<arrayObj.length;i++)
		 {
			if(arrayObj[i]!='')
			{
				fileName = fso.FileExists(arrayObj[i]+":"+AMR_sqliteDbFilePath); 
				if (fileName){
					filePath=arrayObj[i]+":"+AMR_sqliteDbFilePath;
					break;
				}
	
			}
		 }
		 
		return filePath;
		 
	 }
    
	/**
	 * 调用js的fso写入内容到文本文件

	 * @param {Object} filename
	 * @param {Object} filecontent
	 */
	function writeFile(filename,filecontent){ 
		var fso, f, s ; 
		fso = new ActiveXObject("Scripting.FileSystemObject"); 
		f = fso.OpenTextFile(filename,2,true);//2- 覆盖写入 8-追加写入
		f.WriteLine(filecontent); 
		f.Close(); 
		 
	} 
	/** 
	 *显示等待提示层

     */
    function showWaitDiv(strValue)
    {
    	$("#bag1").css({display:"block",width:"100%",height:$(window).height()}).appendTo("body");     
        $("#bag2").html(strValue).appendTo("body").css({display:"block",  
                                         left:($(document.body).outerWidth(true) - 190) / 2,top:($(window).height() - 45) / 2});
    }    
    /** 
	 *隐藏等待提示层

     */
    function hideWaitDiv()
    {
    	document.getElementById("bag1").style.display="none";
    	document.getElementById("bag2").style.display="none"; 	
    }
    
    
     /** 
	 *js获得上下文路径


     */
    function getContextPath(){
          var contextPath = document.location.pathname;
          var index =contextPath.substr(1).indexOf("/");
          contextPath = contextPath.substr(0,index+1);
          delete index;
          return contextPath;
     }
     
     /** 
	 *打印页面数据

     */
     function printPage(ywid,ywtype){
      var url =getContextPath()+"/wxfee/printDate.action?ywid="+ywid+"&ywtype="+ywtype;
      window.showModalDialog(url,"window","dialogWidth:1024px;DialogHeight=768px;status:no;help:no;resizable:no;toolbar=no; menubar=no;"); 
     }

	/*用户状态的转换*/
	userStateTruc = function(state) {
		switch (Number(state)) {
		case 1:
			return "生效";
		case 2:
			return "暂停";
		case 3:
			return "销户";
		case 4:
			return "补/退款未结清";
		case 5:
			return "已安装";
		case 6:
			return "未安装";
		case 7:
			return "已安装未组网";
		default:
			return "未知状态";
		}
	} ;
	/**
	 * 去除字符串两边的空白符
	 * @param {Object} str
	 * @return {TypeName} 
	 */
	function Trim(str) {
          return str.replace(/^\s+|\s+$/g, ""); 
     }
	/**
	 * js 过滤特殊字符
	 * @param {Object} s
	 * @return {TypeName} 
	 */
	function checkAllTextValid(obj) 
	{ 
		  var s = obj.value;
		  s = Trim(s);		  
		 var pattern = new RegExp("[`~!@#$^&*=|{}':;',\\[\\]<>/?~！@#￥……&*——|{}‘；：”“'。，、？]") 
		 var rs = ""; 
		 for (var i = 0; i < s.length; i++) { 
			rs = rs+s.substr(i, 1).replace(pattern, ''); 
		  } 
		 obj.value =  rs;  
	}
	/**
	 * 转换时间YYYY-MM-dd->YYYYMMdd
	 * @param {Object} str
	 * @return {TypeName} 
	 */
	function formatdateForStr(str) {
		if(str!="" && str!=0){
			 return str.replace(/\-/g,'');
		}
		return str;
     }
	
	/**
	 * js获取当前yyyy-MM-dd HH:mm:SS格式时间
	 * @return {TypeName} 
	 */
     function getNowFormatDate() {
	    var date = new Date();
	    var seperator1 = "-";
	    var seperator2 = ":";
	    var month = date.getMonth() + 1;
	    var strDate = date.getDate();
	    var strHour = date.getHours();
	    var strMinute = date.getMinutes();
	    var strSecond = date.getSeconds();
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    if (strDate >= 0 && strDate <= 9) {
	        strDate = "0" + strDate;
	    }
	    if(strHour >= 0 && strHour <=9) {
	        strHour = "0" + strHour;
	    }
	    if(strMinute >=0 && strMinute <=9) {
	        strMinute = "0" + strMinute;
	    }
	    if(strSecond >=0 && strSecond <=9) {
	        strSecond = "0" + strSecond;
	    }
	    var currentdate = date.getYear() + seperator1 + month + seperator1 + strDate
	            + " " + strHour + seperator2 + strMinute
	            + seperator2 + strSecond;
	    return currentdate;
    } 
     
      /**
       * 去除文本域中换行 将换行换成" "
       * @param {Object} key
       * @return {TypeName} 
       */
	   function clearBr(key) 
		{ 
		    key = key.replace(/<\/?.+?>/g," "); 
		    key = key.replace(/[\r\n]/g, " "); 
		    return key; 
		} 
	   loadComboboxData = function(id,url,required,disabled){
			$('#'+id).combobox({
				url:url,
				valueField:'id',
				textField:'text', 
				required:required,
				disabled:disabled
			});
		};
	      /**  
	        * 指定位置显示$.messager.show  
	        * options $.messager.show的options  
	        * param = {left,top,right,bottom}  
	        */ 
	       $.extend($.messager, {  
	           showBySite : function(options,param) {  
	               var site = $.extend( {  
	                   left : "",  
	                   top : "",  
	                   right : 0,  
	                   bottom : -document.body.scrollTop  
	                           - document.documentElement.scrollTop  
	               }, param || {});  
	               var win = $("body > div .messager-body");  
	               if(win.length<=0)  
	                   $.messager.show(options);  
	               win = $("body > div .messager-body");  
	               win.window("window").css( {  
	                   left : site.left,  
	                   top : site.top,  
	                   right : site.right,  
	                   zIndex : $.fn.window.defaults.zIndex++,  
	                   bottom : site.bottom  
	               });  
	           }  
	       }); 

   /**
    *
    *  获取页面所有input输入框的值组合成JSON格式传送到数据，以提交到后台用
    *
    */
   function getJSONParam() {
   	var restr = "";
   	var fields = $(":input").serializeArray();
   	jQuery.each(fields, function(i, field) {
   		if (field.type != "button" || field.type != "img") {
   			if (i == fields.length - 1)
   				restr += "'" + field.name + "'" + ":'" + field.value + "'";
   			else
   				restr += "'" + field.name + "'" + ":'" + field.value + "',";
   		}
   	});
   	var encode = encodeURI(restr);
   	var json = eval('({' + encode + '})')
   	return json;
   }
/**
 *
 * 关闭父窗口，#tt的tab页
 * 
 * 参数：tit 标题    url tab页连接   tabs 所在区域id
 */
function closeParentTTTab() {
	parent.$('#tt').tabs('close', parent.$('#tt').tabs('getSelected').panel('options').title);
}


function isEmpty(str){
	return str==undefined || str==null || str=="null" ||  $.trim(str).length == 0
}



//弹出加载层
function load() {
	$("<div class=\"datagrid-mask\"></div>").css({
		display: "block",
		width: "100%",
		height: $(window).height()
	}).appendTo("body");
	$("<div class=\"datagrid-mask-msg\"></div>").html("加载中，请稍候。。。").appendTo("body").css({
		display: "block",
		left: ($(document.body).outerWidth(true) - 190) / 2,
		top: ($(window).height() - 45) / 2
	});
}
//取消加载层
function disLoad() {
	$(".datagrid-mask").remove();
	$(".datagrid-mask-msg").remove();
}